home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C16 / Stemp2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  557 b   |  28 lines

  1. //: C16:Stemp2.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Non-inline template example
  7. #include "../require.h"
  8.  
  9. template<class T>
  10. class Array {
  11.   static const int size = 100;
  12.   T A[size];
  13. public:
  14.   T& operator[](int index);
  15. };
  16.  
  17. template<class T>
  18. T& Array<T>::operator[](int index) {
  19.   require(index >= 0 && index < size,
  20.     "Index out of range");
  21.   return A[index];
  22. }
  23.  
  24. int main() {
  25.   Array<float> fa;
  26.   fa[0] = 1.414;
  27. } ///:~
  28.